package com.linwen.tips.annotation;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class PermissionAspect {

    @Before("@annotation(requiresPermission)")
    public void checkPermission(RequiresPermission requiresPermission) {
        String permission = requiresPermission.value();

        if (!User.hasPermission(permission)) {
            throw new SecurityException("Insufficient permission to access this resource.");
        }
    }
}


